/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class ShiftingLetters {
	public String shiftingLetters(String S, int[] shifts) {
		char[] cs = S.toCharArray();
		int n = shifts.length;
		long cnt = 0;
		for (int i = n - 1; i >= 0; i--) {
			cnt += shifts[i];
			cs[i] = shift(cs[i], cnt);
		}
		return new String(cs);
	}

	private char shift(char c, long cnt) {
		cnt %= 26;
		c += cnt;
		if (c > 'z') {
			c -= 26;
		}
		return c;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String S = "mkgfzkkuxownxvfvxasy";
		int[] shifts = { 505870226, 437526072, 266740649, 224336793, 532917782, 311122363, 567754492, 595798950,
				81520022, 684110326, 137742843, 275267355, 856903962, 148291585, 919054234, 467541837, 622939912,
				116899933, 983296461, 536563513 };
		// { 3, 5, 9 };
		System.out.println(new ShiftingLetters().shiftingLetters(S, shifts));
	}

}
